<template>
  <div class="dashboard-container">
    <h2 style="text-align: center">{{ infoTitle }}</h2>
    <el-steps
      :active="active"
      finish-status="success"
      align-center
      process-status="wait"
      style="margin-bottom: 40px"
    >
      <el-step title="填写课程基本信息"></el-step>
      <el-step title="创建课程大纲"></el-step>
      <el-step title="提交审核"></el-step>
    </el-steps>

    <el-form label-width="120px">
      <div class="ccInfo">
        <!-- 课程图片 -->
        <img :src="course.cover" />
        <div class="main">
          <!-- 课程标题 -->
          <h2>{{ course.title }}</h2>
          <p class="gray">
            <!-- 课时数 -->
            <span>共{{ course.lessonNum }}课时</span>
          </p>
          <p>
            <!-- 所属分类 -->
            <span
              >所属分类：{{ course.subjectLevelOne }} —
              {{ course.subjectLevelTwo }}</span
            >
          </p>
          <!-- 讲师 -->
          <p>课程讲师：{{ course.teacherName }}</p>
          <!-- 价格 -->
          <h3 class="red">￥{{ course.price }}</h3>
        </div>
      </div>
      <el-form-item>
        <el-button @click="previous">返回修改</el-button>
        <el-button type="primary" @click="publish">发布课程</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import courseApi from "@/api/course";
export default {
  components: {},
  data() {
    return {
      infoTitle: "发布新课程",
      active: 3,
      course: {
        courseId: null,
        cover: null,
        title: null,
        lessonNum: null,
        subjectLevelOne: null,
        subjectLevelTwo: null,
        teacherName: null,
        price: null,
      },
    };
  },
  created() {
    this.init();
  },
  watch: {
    $route(to, from) {
      this.init();
    },
  },
  methods: {
    getCourseAndTeacherById(courseId) {
      courseApi
        .getCourseAndTeacherById(courseId)
        .then((res) => {
          this.course = res.data.course;
        })
        .catch((err) => {});
    },
    //发布课程事件
    publish() {
      this.course.courseId = parseInt(this.course.courseId);
      courseApi
        .publishCourse(this.course.courseId)
        .then((res) => {
          this.$message({
            type: "success",
            message: "发布课程成功!",
          });
          this.$router.push({ path: "/course/showCourse/" });
        })
        .catch((err) => {
          this.$message({
            type: "error",
            message: "删除失败!",
          });
          this.$router.push({ path: "/course/showCourse/" });
        });
    },

    init() {
      if (this.$route.params && this.$route.params.id) {
        this.course.courseId = this.$route.params.id;
        this.getCourseAndTeacherById(this.course.courseId);
      }
    },
    //上一步返回 章节与小节页面
    previous() {
      this.$router.push({
        path: "/course/addChapter/" + this.$route.params.id,
      });
    },
  },
};
</script>

<style >
.ccInfo {
  background: #f5f5f5;
  padding: 20px;
  overflow: hidden;
  border: 1px dashed #ddd;
  margin-bottom: 40px;
  position: relative;
}
.ccInfo img {
  background: #d6d6d6;
  width: 500px;
  height: 278px;
  display: block;
  float: left;
  border: none;
}
.ccInfo .main {
  margin-left: 520px;
}
.ccInfo .main h2 {
  font-size: 28px;
  margin-bottom: 30px;
  line-height: 1;
  font-weight: normal;
}
.ccInfo .main p {
  margin-bottom: 10px;
  word-wrap: break-word;
  line-height: 24px;
  max-height: 48px;
  overflow: hidden;
}
.ccInfo .main p {
  margin-bottom: 10px;
  word-wrap: break-word;
  line-height: 24px;
  max-height: 48px;
  overflow: hidden;
}
.ccInfo .main h3 {
  left: 540px;
  bottom: 20px;
  line-height: 1;
  font-size: 28px;
  color: #d32f24;
  font-weight: normal;
  position: absolute;
}
</style>